<?php
header('Content-Type: application/json');

$dataFile = '../../data/feedback.json';

try {
    if (!isset($_GET['id'])) {
        throw new Exception('缺少ID参数');
    }
    
    $id = $_GET['id'];
    $data = json_decode(file_get_contents($dataFile), true);
    
    // 更新状态为已处理
    $updated = false;
    foreach ($data['feedback'] as &$item) {
        if ($item['id'] == $id) {
            $item['status'] = 'processed';
            $updated = true;
            break;
        }
    }
    
    if (!$updated) {
        throw new Exception('未找到指定意见');
    }
    
    file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT));
    
    echo json_encode(['success' => true]);
    
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?> 